<!DOCTYPE html>
<html>

	<head>
		<meta charset="utf-8">
		<link rel="stylesheet" type="text/css" href="../../../Themes/default/easyui.css">
		<link rel="stylesheet" type="text/css" href="../../../Themes/icon.css">
		<link rel="stylesheet" type="text/css" href="../../../CSS/demo.css">
		<link rel="stylesheet" type="text/css" href="../../../CSS/common.css">
		<link rel="stylesheet" type="text/css" href="../../../CSS/login.css" />
	</head>

	<body style="background-color: white">
		<div style="text-align: center;">
			<form id="ff" method="post">
				<table style="margin-left: 10px;">
					<tr>
						<td width="45%">
							<strong>&nbsp;用户名：</strong>
						</td>
						<td width="55%">
							<input id="input_USERNAME" name="USERNAME" class="easyui-textbox" style="width:100%;" />
						</td>
					</tr>
					<tr>
						<td height="40px"><strong>&nbsp;原密码：</strong></td>
						<td><input type="password" class="easyui-textbox" id="input_PASSWORD_OLD" name="PASSWORD_OLD" style="width:100%;" data-options="required:true" /></td>
					</tr>
					<tr>
						<td height="40px"><strong>&nbsp;新密码：</strong></td>
						<td><input class="easyui-textbox" type="password" data-options="required:true" id="password1" style="width:100%;" /></td>
					</tr>
					<tr>
						<td><strong>密码强度：</strong></td>
						<td>
							<table cellspacing="0px" text-align="center" style="margin-left: 0px;">
								<td id="pwd_Weak" class="pwd pwd_c"> </td>
								<td id="pwd_Medium" class="pwd pwd_c pwd_f">无</td>
								<td id="pwd_Strong" class="pwd pwd_c pwd_c_r"> </td>
							</table>
						</td>
					</tr>
					<tr>
						<td height="40px"><strong>确认密码：</strong></td>
						<td><input type="password" name="PASSWORD" class="easyui-textbox" data-options="required:true" id="input_PASSWORD" style="width:100%;height:25px;" /></td>
					</tr>
					<tr class="flip">
						<td><strong>&nbsp;验证码：</strong></td>
						<td><input id="forget_inputCode" class="easyui-textbox" data-options="prompt:'点击输入验证码',required:true" type="text" style="width:100%;height:25px;" /></td>
					</tr>

					<tr>
						<td style="height:30px;text-align: center;" colspan="3" class="_code" id="checkCode" onclick="createCode()"></td>
					</tr>
					<tr class="hiddentr">
						<td><input class="easyui-textbox" id="input_ID" name="ID"></td>
					</tr>
				</table>
			</form>
			<div style="text-align: center">
				<a class="easyui-linkbutton" id="confirm_password" style="width: 100px;">完成 </a>
				<a class="easyui-linkbutton" id="cancel_password" style="margin-left: 10px;width: 100px;"> 取消</a>
			</div>
		</div>
	</body>
	<script type="text/javascript" src="../../../JS/jquery.min.js"></script>
	<script type="text/javascript" src="../../../JS/jquery.easyui.min.js"></script>
	<script type="text/javascript" src="../../../JS/common.js"></script>
	<script type="text/javascript" src="../../../JS/checkCode.js"></script>
	<script type="text/javascript" src='../../../JS/SHA-1.js'></script>
	<script type="text/javascript">
		var code;
		$(function() { ///初始化事件
			var _username;
			var _userID;
			var _localData = localStorage.getItem("currUser");
			if(_localData != null) {
				s = JSON.parse(_localData);
				_username = s.USERNAME;
				_userID = s.ID;
				$("#input_USERNAME").textbox("setValue", _username);
				$("#input_USERNAME").textbox("readonly", true);
				$("#input_ID").textbox("setValue", _userID);
			} else {
				$.messager.alert("警告", "未能获取到当前登录用户信息，请重新登录");
			}

			$("#password1").textbox({
				onChange: function(newValue, oldValue) {
					console.log(newValue);
					console.log("密码检测");
					CheckIntensity(newValue);
				}
			})

		});

		function CheckIntensity(newValue) {
			var pwd = newValue;
			var Mcolor, Wcolor, Scolor, Color_Html;
			var m = 0;
			var Modes = 0;
			for(i = 0; i < pwd.length; i++) {
				var charType = 0;
				var t = pwd.charCodeAt(i);
				if(t >= 48 && t <= 57) {
					charType = 1;
				} else if(t >= 65 && t <= 90) {
					charType = 2;
				} else if(t >= 97 && t <= 122) {
					charType = 4;
				} else {
					charType = 4;
				}
				Modes |= charType;
			}
			for(i = 0; i < 4; i++) {
				if(Modes & 1) {
					m++;
				}
				Modes >>>= 1;
			}
			if(pwd.length <= 4) {
				m = 1;
			}
			if(pwd.length <= 0) {
				m = 0;
			}
			switch(m) {
				case 1:
					Wcolor = "pwd pwd_Weak_c";
					Mcolor = "pwd pwd_c";
					Scolor = "pwd pwd_c pwd_c_r";
					Color_Html = "弱";
					break;
				case 2:
					Wcolor = "pwd pwd_Medium_c";
					Mcolor = "pwd pwd_Medium_c";
					Scolor = "pwd pwd_c pwd_c_r";
					Color_Html = "中";
					break;
				case 3:
					Wcolor = "pwd pwd_Strong_c";
					Mcolor = "pwd pwd_Strong_c";
					Scolor = "pwd pwd_Strong_c pwd_Strong_c_r";
					Color_Html = "强";
					break;
				default:
					Wcolor = "pwd pwd_c";
					Mcolor = "pwd pwd_c pwd_f";
					Scolor = "pwd pwd_c pwd_c_r";
					Color_Html = "无";
					break;
			}
			document.getElementById('pwd_Weak').className = Wcolor;
			document.getElementById('pwd_Medium').className = Mcolor;
			document.getElementById('pwd_Strong').className = Scolor;
			document.getElementById('pwd_Medium').innerHTML = Color_Html;
		}

		$("#confirm_password").click(function() {
			if(Check_forget_Password()) {
				var data = submitFormData();
				data.PASSWORD=hex_sha1(data.PASSWORD);
				data.PASSWORD_OLD=hex_sha1(data.PASSWORD_OLD);
				_url = RemoteLinkAddress + "/user/updatepsw.do";
				$.post(_url, data,
					function(result) {
						if(result.msg == "success") {
							$.messager.alert({ // show error message
								title: '成功',
								msg: '修改成功'
							});
						} else {
							$.messager.alert({ // show error message
								title: '错误',
								msg: "密码修改失败"
							});
						}
					},
					'json');
			}
		});

		function Check_forget_Password() {
			var forget_inputCode = $("#forget_inputCode").val();
			var regular_forget_password = /^[a-zA-Z]\w{5,17}$/;
			var forget_password1 = $("#password1").val();
			if($("#password1").val().length == 0) {
				$.messager.alert("错误提示", "请输入密码!");
				return false;
			}
			if(!regular_forget_password.test(forget_password1) && $("#password1").val().length < 5) {
				$.messager.alert("错误提示", "密码太短,密码由6~18位字母和数字组成!");
				return false;
			}
			if(!regular_forget_password.test(forget_password1) && $("#password1").val().length > 5) {
				$.messager.alert("错误提示", "密码必须以字母开头,密码由6~18位字母和数字组成!");
				return false;
			}
			if($("#input_PASSWORD").val().length == 0) {
				$.messager.alert("错误提示", "请确认密码!");
				return false;
			}
			if($("#password1").val() != $("#input_PASSWORD").val()) {
				$.messager.alert("错误提示", "两次输入的密码不一致!");
				return false;
			}
			if(forget_inputCode.length <= 0) //判断输入长度
			{
				$.messager.alert("错误提示", "请输入验证码！");
				return false;
			}
			if(forget_inputCode.toUpperCase() != _code.toUpperCase()) {
				$.messager.alert("错误提示", "验证码输入有误！");
				return false;
			}
			return true;
		}
	</script>

</html>